<div class="row">
    <div class="col-lg-12">
        <h3 class="page-header">Danh sách thông báo của các kinh doanh gửi tới</h3>
    </div>
</div>
<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default"> 
            <div class="panel-body">
                <div class="table-reponsive">
                    <a class="" href="<?php echo $this->url(array("action"=>"address1")) ?>">  <p> <button type="reset" class="btn btn-default" id ="answer">Danh sách tin gửi tới cán bộ kinh doanh</button></a></p>
                    <form name="add_question" id="add_question" action="<?php echo $this->url(array("action"=>"index")) ?>">
                        <table name="list_question" id="list_question" class="table table-hover">
                            <tr class="success">
                                    <th>Chọn</th><th>Tên người gửi</th><th>Tiêu đề</th><th>Nội dung</th><th>Nội dung trả lời</th><th>Tình Trạng</th>
                              </tr>
                              <?php 
                                 foreach($this->data as $item){
                                     if($item->getQuestion()==""){
                                         $tinhtrang="Mới";
                                     }elseif ($item->getQuestion()!=""){
                                         $tinhtrang="Đã trả lời";
                                     } 
                                     //nếu không cho trả lời thì($item->getUser_Id()==0)||
                                     if(($item->getQuestion()!="")&&($item->getUser_Id()!=0)){
                                          $strtam="<td class=\"a\"id=\"abc".$item->getId()."\"></td>";
                                     }elseif(($item->getQuestion()=="")||($item->getUser_Id()==0)){ 
                                          $strtam="<td class=\"a\"id=\"abc".$item->getId()."\"><input type=\"checkbox\" name=\"select_question\"id=\"ck".$item->getId()."\"></td>";
                                     }
                                     //chi cho nhung user thuoc vung cua kinh doanh do quan ly xem                                     
                                    // $strtam="<td class=\"a\"id=\"abc".$item->getId()."\"><input type=\"checkbox\" name=\"select_question\"></td>";
                                     foreach ($this->list_kd_user as $val){
                                         if($val->getId()== $item->getAdmin_Id()){ 
                                             if(substr($item->getTitle(),0,1)=="T"){
                                                   echo " <tr>
                                                    ".$strtam."
                                                     <td class=\"u\">".GlobalLib::getName("admin", $item->getAdmin_Id(), "user_name")."</td>
                                                     <td class=\"t\">".substr($item->getTitle(),1)."</td>
                                                     <td class=\"q\" >".$item->getAnswer()."</td>
                                                     <td class=\"q\" >".$item->getQuestion()."</td>
                                                     <td class=\"q\" >".$tinhtrang."</td>
                                                     </tr>";
                                             }
                                            //xu ly du lieu dau ra 
//                                             
//                                            $getQuestion=$item->getQuestion();
//                                            $viTri_SOTU=strpos($getQuestion,"SOTU:");
//                                            $vitri_NOIDUNG=strpos($getQuestion,"NOIDUNG:");
//                                            $ID;
//                                            $SOTU;
//                                            $NOIDUNG;
//                                            $ID = substr($getQuestion,3,$viTri_SOTU-3);
//                                            $SOTU = substr($getQuestion,$viTri_SOTU+5,$vitri_NOIDUNG-$viTri_SOTU-5);
//                                            $NOIDUNG = substr($getQuestion,$vitri_NOIDUNG+8,strlen($getQuestion)-$vitri_NOIDUNG-8 );
//                                            //tao ra hai mang ID,SOTU
//                                            //bo dau ',' dung sau
//                                             $ID=  substr(trim($ID),0, strlen($ID)-1);
//                                             $SOTU= substr(trim($SOTU),0, strlen($SOTU)-1);
//                                            //tao mang 
//                                             $arrID = explode(',',  trim($ID));
//                                             $arrSOTU= explode(',',trim($SOTU));
//                                             $dem1=1;$dem2=1;$arrID_SOTU;
//                                             $i=1;$j=1;
                                            // echo trim($ID);
                                            //  echo trim($SOTU);
//                                             if($item->getUser_Id()==0){
//                                                 
//                                                 foreach ($arrID as $nId){
//                                               //echo "id". $nId;
//                                                 $dem1++;
//                                                
//                                                 foreach ($arrSOTU as $nSotu){  
//                                                    $dem2++; 
//                                                  //  echo "id". $nId;
//                                                  //  echo "sotu".$nSotu;
//                                                    $arrID_SOTU[$i++][$j++]=$nId.','.$nSotu;
//                                                   // echo $arrID_SOTU[1][2];
//                                                   $tam=1;
                                                  
//                                                   if($dem1==$dem2){
//                                                        echo 'so tu:'.$nSotu;
//                                                        $str=$NOIDUNG;
//                                                        while ($tam<$nSotu){
//                                                        $ts=strpos($str," ");
//                                                        $tx= substr($str,0,$ts);
//                                                        $str= trim(substr($str,$ts));
//                                                      // echo "chuoi cat ra:".$tx;
//                                                        echo "chuoi cat :".  $tx;
//                                                        $tam++;
//                                                    }
//                                                   }
//                                                   
//                                                 }
//                                             }
                                             //lay du lieu trong mang ra
                                            
//                                             for($i=1;$i<=3;$i++){
//                                                 for($j=1;$j<=3;$j++){
//                                                    echo $arrID_SOTU[$i][$j];
//                                                 }
//                                             }
//                                             }
                                             
                                            
                                         }
                                     }
                                     //
                                  }
                               ?>
                        </table>
                        <div>
                            <?php 
//                                foreach ($this->list_kd_user as $val){
//                                echo $val->getId();
//                                echo $val->getUserName();  
//                                  } 
                            ?>
                        </div>
                        <input type ="hidden" name="list_selectQuestion" id="list_selectQuestion" value="" ></br>
                         <?php 
                           //  echo $this->paginationControl($this->data, 'Sliding' , 'feedback/pagination.phtml'); 
                             ?></br>
                        <div class="form-group"><center>
                                <button type="submit" class="btn btn-default"id="submit">Chọn</button>
                               <a class="" href="<?php echo $this->url(array("action"=>"listanswer")) ?>">   <button type="button" class="btn btn-default" id ="button">Trở Về</button></a></center>
                        </div>
                    </form>    
                </div>
               
            </div>
        </div>
    </div>
</div>  
<script type="text/javascript"> 
    <?php  foreach ($this->data as $item){ ?> 
     $("#ck"+"<?php echo $item->getId() ?>").click(function(){
          if( $("#ck"+"<?php echo $item->getId() ?>").is(':checked')){
             $("#list_selectQuestion").val($("#list_selectQuestion").val()+"<?php echo $item->getId()?>"+",");           
          }else{
              var t="<?php echo $item->getId()?>"+","; 
              var str = $("#list_selectQuestion").val();
                  str=str.replace(t,"");
              $("#list_selectQuestion").val(str);
          }
   });
    <?php }?>
</script>
<script type="text/javascript">
    $('#submit').click(function(){
        if($('#list_selectQuestion').val()==""){           
            event.preventDefault(); 
            return bootbox.alert("Bạn vừa không chọn câu thông báo nào!");
            return window.location="<?php echo $this->baseUrl() ?>/default/feedback/address";
        }
    });
</script>
